package com.lly.songhigh.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lly.songhigh.R;
import com.lly.songhigh.entity.SearchSinger;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;
import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by 李海龙 on 15/10/27.
 */
public class SearchSingerListViewAdapter extends BaseAdapter {

    private List<SearchSinger.DataEntity> dataEntities;
    private Context context;

    public SearchSingerListViewAdapter(Context context, List<SearchSinger.DataEntity> dataEntities) {
        this.context = context;
        this.dataEntities = dataEntities;
    }

    @Override
    public int getCount() {
        return dataEntities != null && dataEntities.size() > 0 ? dataEntities.size() : 0;
    }

    @Override
    public SearchSinger.DataEntity getItem(int position) {
        return dataEntities.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.search_singer_item, null);
            holder = new ViewHolder();
            holder.searchSingerHead = (CircleImageView) convertView.findViewById(R.id.search_singer_head);
            holder.searchSingerSpecialAlbumCount = (TextView) convertView.findViewById(R.id.search_singer_specialAlbumCount);
            holder.searchSingerName = (TextView) convertView.findViewById(R.id.search_singer_name);
            holder.searchSingerSinglesongCount = (TextView) convertView.findViewById(R.id.search_singer_singlesongCount);
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        SearchSinger.DataEntity dataEntity = getItem(position);
        holder.searchSingerName.setText(dataEntity.getSinger_name());
        holder.searchSingerSinglesongCount.setText(dataEntity.getSong_num() + "首单曲");
        holder.searchSingerSpecialAlbumCount.setText(dataEntity.getAlbum_num() + "张专辑");
        Picasso.with(context).load(dataEntity.getPic_url()).placeholder(R.mipmap.img_music_default_icon)
                .error(R.mipmap.img_music_default_icon).into(holder.searchSingerHead);
        return convertView;

    }

    /**
     * This class contains all butterknife-injected Views & Layouts from layout file 'search_singer_item.xml'
     * for easy to all layout elements.
     *
     * @author ButterKnifeZelezny, plugin for Android Studio by Avast Developers (http://github.com/avast)
     */
//    static class ViewHolder {
//        @Bind(R.id.search_singer_head)
//        CircleImageView searchSingerHead;
//        @Bind(R.id.search_singer_name)
//        TextView searchSingerName;
//        @Bind(R.id.search_singer_singlesongCount)
//        TextView searchSingerSinglesongCount;
//        @Bind(R.id.search_singer_specialAlbumCount)
//        TextView searchSingerSpecialAlbumCount;
//        @Bind(R.id.search_singer_righttArr)
//        ImageView searchSingerRighttArr;
//
//        ViewHolder(View view) {
//            ButterKnife.bind(this, view);
//        }
//    }

    private class ViewHolder{
        private CircleImageView searchSingerHead;
        private TextView searchSingerName;
        private TextView searchSingerSinglesongCount;
        private TextView searchSingerSpecialAlbumCount;
        private ImageView searchSingerRighttArr;

    }
}
